package com.liu.yupao.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lqh
 * @since 2025-09-28 20:40
 * redisson配置类
 */
@Configuration
@ConfigurationProperties(prefix = "spring.redis")  //从配置文件中获取
@Data
public class RedissonConfig {

    private String host;

    private String port;

    //创建redisson客户端
    @Bean  //被spring托管 之后可以使用resource注解去获取这个bean
    public RedissonClient redissonClient(){
        //创建连接
        Config config = new Config();
        String redisAddress=String.format ("redis://%s:%s",host,port);
        config.useSingleServer ().setAddress (redisAddress).setDatabase (2);
        //创建客户端
        // Sync and Async API
         return Redisson.create(config);
    }

}
